<template>
  <KiFormDialog
    :show.sync="dialogVisible"
    title="预订确认"
    :loading="inRequest"
    :submit="confirm"
  >
    <div v-if="info" class="text-18px">
      <p>{{ info.orderId }} {{ info.productName }}，数量{{ info.quantity }}</p>
      <p>入住日期：{{ info.useStartTime }}</p>
      <p>离店日期：{{ info.useEndTime }}</p>
      <p>确定进行预订？</p>
    </div>
  </KiFormDialog>
</template>
<script>
import API from './api'
export default {
  data () {
    return {
      dialogVisible: false,
      orderId: '',
      inRequest: false,
      info: null
    }
  },
  methods: {
    open (orderId) {
      this.orderId = orderId
      this.dialogVisible = true

      API.getOrderInfo({
        orderId
      }).then(({ data }) => {
        this.info = data
      })
    },
    confirm () {
      this.inRequest = true
      API.acceptOrder({
        orderId: this.orderId
      })
        .then(({ data }) => {
          this.$swal.success('操作成功')
          this.$emit('save')
          this.dialogVisible = false
          this.inRequest = false
        })
        .catch(() => {
          this.inRequest = false
        })
    }
  }
}
</script>
